{% load static humanize %}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ product.name }} - 智淘go</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        :root {
            --primary: rgba(255, 107, 107, 0.3);
            --secondary: #4ECDC4;
            --text-dark: #2D3436;
            --text-light: #636E72;
            --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }

        body {
            background: url('https://pic2.zhimg.com/v2-86ffa1ad12c00587d5cb6f9bd362578a_r.jpg?source=1940ef5c') no-repeat center center fixed;
            font-family: 'Helvetica Neue', Arial, 'Microsoft YaHei', sans-serif;
            background-color: #f8fafc;
        }

        .product-detail {
            max-width: 1200px;
            margin: 2rem auto;
            padding: 0 1rem;
        }

        .back-link {
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
            color: var(--text-light);
            text-decoration: none;
            margin-bottom: 2rem;
            transition: color 0.3s ease;
        }

        .back-link:hover {
            color: var(--primary);
        }

        .gallery-container {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 3rem;
            margin-top: 2rem;
        }

        .main-image {
            width: 100%;
            height: 500px;
            object-fit: contain;
            background: white;
            border-radius: 16px;
            padding: 2rem;
            box-shadow: var(--shadow);
            cursor: zoom-in;
            transition: transform 0.3s ease;
        }

        .main-image.zoomed {
            transform: scale(1.5);
            cursor: zoom-out;
        }

        .product-info {
            background: white;
            padding: 2rem;
            border-radius: 16px;
            box-shadow: var(--shadow);
        }

        .product-status {
            display: flex;
            align-items: center;
            gap: 1rem;
            margin-bottom: 1.5rem;
        }

        .condition-badge {
            background: var(--primary);
            color: white;
            padding: 0.5rem 1.2rem;
            border-radius: 20px;
            font-size: 0.9rem;
        }

        .views-count {
            color: var(--text-light);
            font-size: 0.95rem;
        }

        .price-tag {
            color: var(--primary);
            font-size: 2.5rem;
            font-weight: 700;
            margin: 2rem 0;
            padding: 1rem 0;
            border-bottom: 2px solid #f1f5f9;
        }

        .description-section {
            margin: 2rem 0;
        }

        .description-section h3 {
            color: var(--text-dark);
            margin-bottom: 1rem;
            font-size: 1.2rem;
        }

        .description-content {
            color: var(--text-light);
            line-height: 1.8;
            white-space: pre-wrap;
        }

        .seller-card {
            background: #f8fafc;
            padding: 2rem;
            border-radius: 12px;
            margin-top: 2rem;
        }

        .seller-header {
            display: flex;
            align-items: center;
            gap: 1rem;
            margin-bottom: 1.5rem;
        }

        .seller-avatar {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background: var(--primary);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
        }

        .seller-name {
            font-size: 1.2rem;
            color: var(--text-dark);
        }

        .seller-meta {
            display: flex;
            gap: 1.5rem;
            margin-bottom: 1.5rem;
        }

        .meta-item {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            color: var(--text-light);
        }

        .contact-panel {
            margin-top: 2rem;
        }

        .contact-btn {
            background: var(--primary);
            color: white;
            border: none;
            padding: 1rem 2rem;
            border-radius: 30px;
            font-size: 1rem;
            cursor: pointer;
            transition: opacity 0.3s ease;
            width: 100%;
        }

        .contact-btn:hover {
            opacity: 0.9;
        }

        .contact-info {
            margin-top: 1.5rem;
            padding: 1.5rem;
            background: white;
            border-radius: 8px;
            border: 1px solid #f1f5f9;
            text-align: center;
            font-size: 1.2rem;
            color: var(--text-dark);
            display: none;
        }

        .sold-alert {
            background: var(--primary);
            color: white;
            padding: 1rem;
            border-radius: 8px;
            text-align: center;
            margin-top: 2rem;
        }

        @media (max-width: 768px) {
            .gallery-container {
                grid-template-columns: 1fr;
            }

            .main-image {
                height: 300px;
            }
        }
        .action-buttons {
            margin: 2rem 0;
        }

        .buy-btn {
            background: var(--primary);
            color: white;
            padding: 1.2rem 3rem;
            border-radius: 30px;
            text-decoration: none;
            display: inline-block;
            font-size: 1.1rem;
            transition: transform 0.2s ease;
            box-shadow: var(--shadow);
        }

        .buy-btn:hover {
            transform: translateY(-2px);
            color: white;
        }
    </style>
</head>
<body>
    <div class="product-detail">
        <a href="{% url 'product_list' %}" class="back-link">
            <i class="fas fa-arrow-left"></i>
            返回商品列表
        </a>

        <div class="gallery-container">
            <img src="{{ product.image.url }}"
                 class="main-image"
                 alt="{{ product.name }}"
                 onclick="toggleZoom()">

            <div class="product-info">
                <div class="product-status">
                    <span class="condition-badge">{{ product.get_condition_display }}</span>
                    <span class="views-count">
                        <i class="fas fa-eye"></i>
                        {{ product.views|intcomma }}次浏览
                    </span>
                </div>

                <div class="price-tag">¥{{ product.price|intcomma }}</div>

                {% if not product.is_sold %}
                <div class="action-buttons">
                    <a href="{% url 'create_order' product.id %}" class="buy-btn">
                        <i class="fas fa-shopping-cart"></i>
                        立即购买
                    </a>
                </div>
                {% endif %}

                <div class="description-section">
                    <h3>商品描述</h3>
                    <pre class="description-content">{{ product.description }}</pre>
                </div>

                <div class="seller-card">
                    <div class="seller-header">
                        <div class="seller-avatar">
                            {{ product.seller_name|first|upper }}
                        </div>
                        <div>
                            <h3 class="seller-name">{{ product.seller_name }}</h3>
                            <div class="meta-item">
                                <i class="fas fa-map-marker-alt"></i>
                                {{ product.location }}
                            </div>
                        </div>
                    </div>

                    <div class="contact-panel">
                        <button class="contact-btn" onclick="showContact()">
                            <i class="fas fa-phone-alt"></i>
                            显示联系方式
                        </button>
                        <div id="contactInfo" class="contact-info">
                            {{ product.contact|default:"暂无联系方式" }}
                        </div>
                    </div>
                </div>

                {% if product.is_sold %}
                <div class="sold-alert">
                    <i class="fas fa-tag"></i>
                    该商品已售出
                </div>
                {% endif %}
            </div>
        </div>
    </div>

    <script>
        // 联系方式显示
        function showContact() {
            const contactInfo = document.getElementById('contactInfo');
            contactInfo.style.display = 'block';
            setTimeout(() => {
                contactInfo.style.opacity = 1;
            }, 10);
        }

        // 图片缩放功能
        function toggleZoom() {
            const image = document.querySelector('.main-image');
            image.classList.toggle('zoomed');
        }

        // 点击外部区域关闭缩放
        document.addEventListener('click', (e) => {
            const image = document.querySelector('.main-image');
            if (!image.contains(e.target) && image.classList.contains('zoomed')) {
                image.classList.remove('zoomed');
            }
        });
    </script>
</body>
</html>